console.log('=== payment initUpload ===');
const { event, root, rootTemplateModel, templateModel, template, meta, utils, logger, services, model
} = pipe; const { big
} = meta; const proposersFamilyName = utils.get(root, 'proposers.0.familyName'); const proposersGivenName = utils.get(root, 'proposers.0.givenName'); const proposersFullNameChi = utils.get(root, 'proposers.0.fullNameChi'); const insuredsFamilyName = utils.get(root, 'insureds.0.familyName'); const insuredsGivenName = utils.get(root, 'insureds.0.givenName'); const insuredsFullNameChi = utils.get(root, 'primaryBeneficiaries.0.fullNameChi'); const uploadInfoMapping = utils.get(template, 'uploadInfoMapping',
    {}); const roleList = {
        'proposers': {
            label: {
                en: `Proposed Policyholder<br/>(${(proposersFamilyName || proposersGivenName) ? `${proposersFamilyName || ''
                    } ${proposersGivenName || ''
                    }` : `${proposersFullNameChi
                    }`
                    })`, tc: `準保單持有人<br/>(${(proposersFamilyName || proposersGivenName) ? `${proposersFamilyName || ''
                        } ${proposersGivenName || ''
                        }` : `${proposersFullNameChi
                        }`
                        })`, sc: `准保单持有人<br/>(${(proposersFamilyName || proposersGivenName) ? `${proposersFamilyName || ''
                            } ${proposersGivenName || ''
                            }` : `${proposersFullNameChi
                            }`
                            })`
            }, files: ['debitAccountProof', 'phPaymentProof', 'fpsDebitAccountProof'
            ]
        }, 'insureds': {
            label: {
                en: `Proposed Insured<br/>(${(insuredsFamilyName || insuredsGivenName) ? `${insuredsFamilyName || ''
                    } ${insuredsGivenName || ''
                    }` : `${insuredsFullNameChi
                    }`
                    })`, tc: `準受保人<br/>(${(insuredsFamilyName || insuredsGivenName) ? `${insuredsFamilyName || ''
                        } ${insuredsGivenName || ''
                        }` : `${insuredsFullNameChi
                        }`
                        })`, sc: `准受保人<br/>(${(insuredsFamilyName || insuredsGivenName) ? `${insuredsFamilyName || ''
                            } ${insuredsGivenName || ''
                            }` : `${insuredsFullNameChi
                            }`
                            })`
            }, files: ['payorIdCopy', 'piPaymentProof'
            ]
        }, 'primaryBeneficiaries': {
            label: {}, files: ['payorIdCopy', 'piPaymentProof'
            ]
        }, 'secondaryBeneficiaries': {
            label: {}, files: ['payorIdCopy', 'piPaymentProof'
            ]
        }
    }; const settingOriginal = {
        cssClass: '', files: [], mandatory: false, min: undefined, max: undefined, supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'application/pdf'
        ], pdf: undefined, beneId: undefined, hideDeleteBtns: [], hideBtns: []
    }; const uploadTemplateVM = {
        'id': '', 'type': 'section', 'cssClass': 'upload-item-container', 'items': [
            {
                'custClass': 'files-upload-container', 'default': [], 'mode': 'inline', 'enableInlineUpload': true, 'hideAddBtn': true, 'useUploadBtnEvent': true, 'hideDeleteBtn': true, 'mode': 'inline', 'displayMode': 'inline', 'buttons': [
                    {
                        'uploadFileBtnLabel': '', 'uploadFileIconImg': 'assets/icons/photo.svg', 'clickActionName': 'takePhotoButtonClick', 'addFileIconImg': 'assets/icons/photo.svg'
                    },
                    {
                        'uploadFileBtnLabel': '', 'uploadFileIconImg': 'assets/icons/upload-file.svg', 'clickActionName': 'uploadFileButtonClick', 'addFileIconImg': 'assets/icons/upload-file.svg'
                    }
                ], 'deleteFileIcon': 'close-outline', 'disablePreviewDialog': true, 'addFileBtnLabel': '', 'pdfIconImg': 'assets/icons/download-file.svg', 'pendingIconImg': 'assets/icons/triangle-top-left.svg', 'completedIconImg': 'assets/icons/triangle-top-left.svg', 'showInlineDownloadBtn': true, 'showWarningIcon': false, 'maxFileSize': 5242880, 'downloadActionName': 'downloadPdf', 'deleteConfirmTitle': {
                    'en': 'Confirm', 'tc': '確定', 'sc': '确定'
                }, 'deleteConfirmMessage': {
                    'en': 'Are you sure you want to delete the file?', 'tc': '您確定要刪除該文件嗎？', 'sc': '您确定要删除该文件吗？'
                }, 'uploadingText': {
                    'en': 'Uploading...', 'tc': '上傳中...', 'sc': '上传中...'
                }, 'optionalLabel': {
                    'en': 'Optional', 'tc': '可選的', 'sc': '可选的'
                }, 'alertOptions': {
                    hideCancelbtn: true, confirmHandler: () => true
                }, 'deleteIconName': 'trash-outline', 'dialogDateFormat': 'YYYY-MM-dd HH:mm', 'id': undefined, 'type': 'filesUpload'
            }
        ]
    }; const uploadListVM = {
        'custClass': 'upload-list-container', 'items': [], 'type': 'section'
    }; const uploadListFieldPath = 'uploadDocumentDialog.body.items.1.items'; utils.set(template, uploadListFieldPath,
        []); let templateContainer = utils.get(template, uploadListFieldPath); const checkRoleByDocId = {}; const rootUploadFiles = utils.get(root, 'attachments.uploadFiles',
            {}); utils.set(root, 'roleList', roleList); const paymentRecords = utils.get(root, 'payment.paymentRecords',
                []); const exchangeRate = utils.get(root, 'quotation.summary.exchangeRate',
                    1); let filesListArrPaymentProof = []; utils.forEach(roleList, (role, key) => {
                        if ((key === 'insureds' && utils.get(root, 'quotation.sameAs'))) {
                            return;
                        } const thisRoles = (utils.get(root, `quotation.${key
                            }`)) || (utils.get(root, `${key
                                }`)); if (!utils.isNil(thisRoles) && utils.isArray(thisRoles) && !utils.isEmpty(thisRoles)) {
                                    utils.forEach(thisRoles, (singleRole, index) => {
                                        if (!utils.isNil(singleRole)) {
                                            const singleRoleName = `${singleRole.familyName || ''
                                                } ${singleRole.givenName || ''
                                                } ${singleRole.fullNameChi || ''
                                                }`; utils.set(checkRoleByDocId, `${key
                                                    }.${index
                                                    }`,
                                                    {
                                                        fullName: singleRoleName, roles: utils.set({}, `${key
                                                            }_${index
                                                            }`), rolesLabel: role.label, relationship: singleRole.relationship,
                                                    }); if (key.includes('Beneficiaries')) {
                                                        const beneficiariesLabel = {
                                                            en: `${key === 'primaryBeneficiaries' ? 'Primary Beneficiary' : 'Secondary Beneficiary'
                                                                }<br/>(${singleRoleName
                                                                })`, tc: `${key === 'primaryBeneficiaries' ? '基本受益人' : '次位受益人'
                                                                    }<br/>(${singleRoleName
                                                                    })`, sc: `${key === 'primaryBeneficiaries' ? '基本受益人' : '次位受益人'
                                                                        }<br/>(${singleRoleName
                                                                        })`
                                                        }; utils.set(checkRoleByDocId, `${key
                                                            }.${index
                                                            }.rolesLabel`, beneficiariesLabel);
                                                    } if ((key === 'proposers' && utils.get(root, 'quotation.sameAs'))) {
                                                        utils.set(checkRoleByDocId, `${key
                                                            }.${index
                                                            }.roles.proposers_${index
                                                            }`, undefined);
                                                    }
                                        }
                                    });
                                }
                    }); if (!utils.isEmpty(checkRoleByDocId)) {
                        utils.forEach(checkRoleByDocId, (list, roleName) => {
                            const listVM = utils.cloneDeep(uploadListVM); utils.forEach(list, (person, roleIndex) => {
                                const thisRoleData = (utils.get(root, `quotation.${roleName
                                    }.${roleIndex
                                    }`)) || (utils.get(root, `${roleName
                                        }.${roleIndex
                                        }`)); if (!utils.isNil(thisRoleData) && person.relationship !== 'CHARITY') {
                                            const itemVM = utils.cloneDeep(uploadTemplateVM); const currentFiles = {}; const thisRoleFiles = utils.get(roleList, `${roleName
                                                }.files`,
                                                []); switch (roleName) {
                                                    case 'proposers': utils.forEach(thisRoleFiles, (file) => {
                                                        const hideDeleteBtns = []; let isShowFile = false; let custSetting = {}; let setting = utils.cloneDeep(settingOriginal); switch (file) {
                                                            case 'debitAccountProof': let phCareditCardPayAmount = 0; paymentRecords.forEach(item => {
                                                                if (item.paidBy === 'PROPOSER' && item.paymentMethod === 'CREDIT_CARD') {
                                                                    phCareditCardPayAmount = +big(phCareditCardPayAmount).plus(item.amount ? item.amount : 0);
                                                                }
                                                            })                   if (+big(phCareditCardPayAmount).times(exchangeRate) > 400000) {
                                                                isShowFile = true;
                                                            } custSetting = {
                                                                hideDeleteBtns, supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'application/pdf'
                                                                ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                            }; break; case 'phPaymentProof': paymentRecords.forEach(item => {
                                                                if (item.paidBy === 'PROPOSER' && item.paymentMethod === 'FPS' && item.amount) {
                                                                    isShowFile = true;
                                                                }
                                                            })                   custSetting = {
                                                                supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'application/pdf'
                                                                ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                            }; break; case 'fpsDebitAccountProof': let phFpsPayAmount = 0; paymentRecords.forEach(item => {
                                                                if (item.paidBy === 'PROPOSER' && item.paymentMethod === 'FPS') {
                                                                    phFpsPayAmount = +big(phFpsPayAmount).plus(item.amount);
                                                                }
                                                            })                   if (+big(phFpsPayAmount).times(exchangeRate) > 400000) {
                                                                isShowFile = true;
                                                            } custSetting = {
                                                                supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'application/pdf'
                                                                ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                            }; break; default: isShowFile = true; break;
                                                        }               if (isShowFile) {
                                                            setting = {
                                                                ...setting, ...custSetting, files: utils.get(rootUploadFiles, `${roleName
                                                                    }.${roleIndex
                                                                    }.${file
                                                                    }`,
                                                                    [])
                                                            }; if (!utils.isNil(setting.pdf) && !utils.isEmpty(setting.pdf)) {
                                                                utils.set(setting, 'cssClass', 'pdf-exist-item');
                                                            } utils.set(currentFiles, file,
                                                                {
                                                                    ...uploadInfoMapping[file
                                                                    ], ...setting
                                                                });
                                                        }
                                                    }); break; case 'insureds': utils.forEach(thisRoleFiles, (file) => {
                                                        const hideDeleteBtns = []; let isShowFile = false; let isMandatory = false; let custSetting = {}; let setting = utils.cloneDeep(settingOriginal); const sameAs = utils.get(root, 'quotation.sameAs'); const thisRoleUploadFilesByFileId = utils.get(root, `attachments.uploadFiles.${sameAs ? 'proposers' : 'insureds'
                                                            }.${roleIndex
                                                            }.idCopy`,
                                                            []); const insuredsFileId = utils.get(root, `attachments.uploadFiles.insureds.${roleIndex
                                                                }.idCopy`,
                                                                []); switch (file) {
                                                                    case 'payorIdCopy': paymentRecords.forEach(item => {
                                                                        if (item.paidBy === 'INSURED') {
                                                                            isShowFile = true;
                                                                        }
                                                                    })                   utils.forEach(thisRoleUploadFilesByFileId, (singleFile) => {
                                                                        if (singleFile.source === 'OCR') {
                                                                            isShowFile = false;
                                                                        }
                                                                    }); if (utils.find(insuredsFileId, item => !utils.isEmpty(item))) {
                                                                        isShowFile = false;
                                                                    } custSetting = {
                                                                        mandatory: isMandatory, hideDeleteBtns, hideBtns: [
                                                                            1
                                                                        ], supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif'
                                                                        ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                                    }; break; case 'piPaymentProof': paymentRecords.forEach(item => {
                                                                        if ((item.paidBy === 'INSURED' || (item.paidBy === 'PROPOSER' && sameAs)) && item.amount) {
                                                                            isShowFile = true;
                                                                        }
                                                                    })                   custSetting = {
                                                                        supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'application/pdf'
                                                                        ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                                    }; break; default: isShowFile = true; break;
                                                                }               if (isShowFile) {
                                                                    setting = {
                                                                        ...setting, ...custSetting, files: utils.get(rootUploadFiles, `${roleName
                                                                            }.${roleIndex
                                                                            }.${file
                                                                            }`,
                                                                            [])
                                                                    }; if (!utils.isNil(setting.pdf) && !utils.isEmpty(setting.pdf)) {
                                                                        utils.set(setting, 'cssClass', 'pdf-exist-item');
                                                                    } utils.set(currentFiles, file,
                                                                        {
                                                                            ...uploadInfoMapping[file
                                                                            ], ...setting
                                                                        });
                                                                }
                                                    }); break; case 'secondaryBeneficiaries': utils.forEach(thisRoleFiles, (file) => {
                                                        const hideDeleteBtns = []; let isShowFile = false; let isMandatory = false; let custSetting = {}; let setting = utils.cloneDeep(settingOriginal); const thisRoleUploadFilesByFileId = utils.get(root, `attachments.uploadFiles.beneficiaries.${roleIndex
                                                            }.idCopy`,
                                                            []); switch (file) {
                                                                case 'payorIdCopy': paymentRecords.forEach(item => {
                                                                    if (item?.paidBy?.includes('SBENEFICIARY') && item.amount && roleIndex === Number(item?.paidBy?.charAt(item.paidBy.length - 1))) {
                                                                        isShowFile = true;
                                                                    }
                                                                })                   utils.forEach(thisRoleUploadFilesByFileId, (singleFile) => {
                                                                    if (singleFile.source === 'OCR') {
                                                                        isShowFile = false;
                                                                    }
                                                                }); custSetting = {
                                                                    mandatory: isMandatory, hideDeleteBtns, hideBtns: [
                                                                        1
                                                                    ], supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif'
                                                                    ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                                }; break; case 'piPaymentProof': paymentRecords.forEach(item => {
                                                                    if (item?.paidBy?.includes('SBENEFICIARY') && item.amount && roleIndex === Number(item.paidBy.charAt(item.paidBy.length - 1))) {
                                                                        isShowFile = true;
                                                                    }
                                                                })                   custSetting = {
                                                                    supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'application/pdf'
                                                                    ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                                }; break; default: isShowFile = true; break;
                                                            }               if (isShowFile) {
                                                                setting = {
                                                                    ...setting, ...custSetting, files: utils.get(rootUploadFiles, `${'beneficiaries'
                                                                        }.${roleName.includes('primaryBeneficiaries') ? roleIndex : roleIndex + checkRoleByDocId?.primaryBeneficiaries?.length
                                                                        }.${file
                                                                        }`,
                                                                        []), beneId: utils.get(rootUploadFiles, `${'beneficiaries'
                                                                            }.${roleName.includes('primaryBeneficiaries') ? roleIndex : roleIndex + checkRoleByDocId?.primaryBeneficiaries?.length
                                                                            }.beneId`,
                                                                            [])
                                                                }; if (!utils.isNil(setting.pdf) && !utils.isEmpty(setting.pdf)) {
                                                                    utils.set(setting, 'cssClass', 'pdf-exist-item');
                                                                } utils.set(currentFiles, file,
                                                                    {
                                                                        ...uploadInfoMapping[file
                                                                        ], ...setting
                                                                    });
                                                            }
                                                    }); break; case 'primaryBeneficiaries': utils.forEach(thisRoleFiles, (file) => {
                                                        const hideDeleteBtns = []; let isShowFile = false; let isMandatory = false; let custSetting = {}; let setting = utils.cloneDeep(settingOriginal); const thisRoleUploadFilesByFileId = utils.get(root, `attachments.uploadFiles.beneficiaries.${roleIndex
                                                            }.idCopy`,
                                                            []); switch (file) {
                                                                case 'payorIdCopy': paymentRecords.forEach(item => {
                                                                    if (item?.paidBy?.includes('PBENEFICIARY') && item.amount && item.amount && roleIndex === Number(item.paidBy.charAt(item.paidBy.length - 1))) {
                                                                        isShowFile = true;
                                                                    }
                                                                })                   utils.forEach(thisRoleUploadFilesByFileId, (singleFile) => {
                                                                    if (singleFile.source === 'OCR') {
                                                                        isShowFile = false;
                                                                    }
                                                                }); custSetting = {
                                                                    mandatory: isMandatory, hideDeleteBtns, hideBtns: [
                                                                        1
                                                                    ], supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif'
                                                                    ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                                }; break; case 'piPaymentProof': paymentRecords.forEach(item => {
                                                                    if (item?.paidBy?.includes('PBENEFICIARY') && item.amount && item.amount && roleIndex === Number(item.paidBy.charAt(item.paidBy.length - 1))) {
                                                                        isShowFile = true;
                                                                    }
                                                                })                   custSetting = {
                                                                    supportTypes: ['image/jpg', 'image/png', 'image/jpeg', 'image/bmp', 'image/gif', 'application/pdf'
                                                                    ], fileTypeNotSupportedMessage: 'ERRORS.ALLOW_UPLOAD_PHOTO_OR_PDF'
                                                                }; break; default: isShowFile = true; break;
                                                            }               if (isShowFile) {
                                                                setting = {
                                                                    ...setting, ...custSetting, files: utils.get(rootUploadFiles, `${'beneficiaries'
                                                                        }.${roleName.includes('primaryBeneficiaries') ? roleIndex : roleIndex + checkRoleByDocId?.primaryBeneficiaries?.length
                                                                        }.${file
                                                                        }`,
                                                                        []), beneId: utils.get(rootUploadFiles, `${'beneficiaries'
                                                                            }.${roleName.includes('primaryBeneficiaries') ? roleIndex : roleIndex + checkRoleByDocId?.primaryBeneficiaries?.length
                                                                            }.beneId`,
                                                                            [])
                                                                }; if (!utils.isNil(setting.pdf) && !utils.isEmpty(setting.pdf)) {
                                                                    utils.set(setting, 'cssClass', 'pdf-exist-item');
                                                                } utils.set(currentFiles, file,
                                                                    {
                                                                        ...uploadInfoMapping[file
                                                                        ], ...setting
                                                                    });
                                                            }
                                                    }); break;
                                                }         if (!utils.isEmpty(currentFiles)) {
                                                    utils.forEach(Object.values(currentFiles), item => {
                                                        item.id = `${item.id
                                                            }-${Object.keys(person.roles).join('-')
                                                            }`;
                                                    });
                                                } utils.set(person, 'filesList', currentFiles); utils.set(itemVM, 'id', `upload-section-${roleName
                                                    }_${roleIndex
                                                    }`); utils.set(itemVM, 'label', utils.get(person, 'rolesLabel')); utils.set(itemVM, 'items.0.id', `${roleName
                                                        }_${roleIndex
                                                        }`); utils.set(itemVM, 'items.0.default', Object.values(currentFiles)); filesListArrPaymentProof = filesListArrPaymentProof.concat(Object.values(currentFiles)); listVM.items.push(itemVM);
                                        }
                            }); if (listVM.items.length > 0) {
                                if (listVM?.items?.length === 1 && !utils.isEmpty(listVM?.items[
                                    0
                                ]?.items[
                                    0
                                ]?.default)) {
                                    templateContainer.push(listVM);
                                } else {
                                    utils.forEach(listVM.items, ele => {
                                        if (!utils.isEmpty(ele?.items[
                                            0
                                        ]?.default)) {
                                            templateContainer.push({
                                                custClass: listVM?.custClass, items: [ele
                                                ], type: listVM?.type,
                                            })
                                        }
                                    })
                                }
                            }
                        });
                    } let showWarningMessage = false; utils.set(meta, 'filesListArrPaymentProof', filesListArrPaymentProof); if (utils.isEmpty(filesListArrPaymentProof)) {
                        utils.set(meta, 'hideUploadButton', true);
                    } else {
    utils.set(meta, 'hideUploadButton', false);
} utils.forEach(filesListArrPaymentProof, item => {
    if (!item.mandatory && utils.isEmpty(item.files)) {
        showWarningMessage = true;
    }
}) if (showWarningMessage) {
    meta.warningsBarDataModel = meta.warningsUtils.addWarnings(meta.warningsBarDataModel,
        [
            {
                type: 'notice', code: 'ERR.SUPPLEMENT_OPTIONAL_DOCUMENT', id: 'optionalDoc'
            }
        ]);
} else {
    meta.warningsBarDataModel = utils.filter(meta.warningsBarDataModel, item => {
        return item.code !== 'ERR.SUPPLEMENT_OPTIONAL_DOCUMENT'
    })
}

// 获取 paymentProofRules
const paymentProofRules = utils.get(template, 'uploadInfoMapping.paymentProofRules', []);

// 金额区间字符串转判断函数
function matchAmount(amount, rangeStr) {
    if (rangeStr.includes('>') && rangeStr.includes('<=') && rangeStr.includes('&')) {
        // 例如 > HKD 120,000 & <= HKD 400,000
        const [min, max] = rangeStr.match(/> HKD ([\d,]+) & <= HKD ([\d,]+)/).slice(1, 3).map(s => +s.replace(/,/g, ''));
        return amount > min && amount <= max;
    }
    if (rangeStr.includes('>')) {
        const min = +rangeStr.match(/> HKD ([\d,]+)/)[1].replace(/,/g, '');
        return amount > min;
    }
    if (rangeStr.includes('<=') && !rangeStr.includes('&')) {
        const max = +rangeStr.match(/<= HKD ([\d,]+)/)[1].replace(/,/g, '');
        return amount <= max;
    }
    return false;
}

// 匹配规则
function findMatchedRule(paymentMethod, amount, highRisk) {
    return paymentProofRules.find(rule =>
        rule.paymentMethod.toUpperCase() === paymentMethod.toUpperCase() &&
        (rule.highRisk === 'Any' || rule.highRisk === highRisk) &&
        matchAmount(amount, rule.amountRange)
    );
}

// 遍历 paymentRecords，按 payor 归类，动态生成材料
const payorMaterials = {};
paymentRecords.forEach(item => {
    const payor = item.paidBy;
    const paymentMethod = item.paymentMethod;
    const amount = +item.amount * exchangeRate;
    // highRisk 需根据你的业务逻辑获取，这里假设为'N'
    const highRisk = 'N';
    const rule = findMatchedRule(paymentMethod, amount, highRisk);
    if (rule) {
        if (!payorMaterials[payor]) payorMaterials[payor] = [];
        rule.documents.forEach(doc => {
            if (!payorMaterials[payor].find(d => d.id === doc.id)) {
                payorMaterials[payor].push(doc);
            }
        });
    }
});

// 你可以用 payorMaterials 生成上传项
// 例如：
// Object.keys(payorMaterials).forEach(payor => {
//   payorMaterials[payor].forEach(doc => {
//     // 渲染上传项
//   });
// });